package org.changchen.fgt.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.changchen.fgt.constant.GlobalConstants;
import org.changchen.fgt.dto.DoubanHotDto;
import org.changchen.fgt.service.DoubanHotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/douban")
public class DoubanController {
	
	
	@Autowired
	private DoubanHotService doubanHotService;
	
	@GetMapping(value = "/hot")
	@ResponseBody
	public List<DoubanHotDto> getDoubanHot(@RequestParam(name = "tag", required = false)String tag, @RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "12")Integer size) {
		return doubanHotService.getDoubanHot(tag!=null?tag:GlobalConstants.TV_TYPE_LIST.get(0), page, size);
	}
	
	
	@GetMapping(value = "/hot/tv")
	@ResponseBody
	public List<DoubanHotDto> getDoubanTv(@RequestParam(name = "tag", required = false)String tag, @RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "12")Integer size) {
		return doubanHotService.getDoubanHotTv(tag!=null?tag:GlobalConstants.TV_TYPE_LIST.get(0), page, size);
	}
	

	@GetMapping(value = "/hot/movie")
	@ResponseBody
	public List<DoubanHotDto> getDoubanMovie(@RequestParam(name = "tag", required = false)String tag, @RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "12")Integer size) {
		return doubanHotService.getDoubanHotMovie(tag!=null?tag:GlobalConstants.TV_TYPE_LIST.get(0), page, size);
	}
	
	
    @GetMapping("/image")
    public void image(HttpServletResponse response, String url) throws IOException {
    	doubanHotService.doubanImage(response, url);
    }
	
	
}
